<template>
  <div id="app">
    <!-- 用户表格 -->
    <user-info v-if="isRouterAlive" ref="userInfo" :router-message="routerMessage" @getStatus="getStatus" />
    <!-- 审核 -->
    <user-examine ref="userExamine" :get-status-type="getStatusType" />
    <!-- 评分 -->
    <user-score ref="userScore" :get-status-type="getStatusType" />
    <!-- 一票否决 -->
    <user-veto ref="userVeto" :get-status-type="getStatusType" />
    <!-- 复核 -->
    <review-send ref="reviewSend" :get-status-type="getStatusType" />
    <!-- 批量审核选中 -->
    <examine-select-score ref="examineSelectScore" :get-status-type="getStatusType" />
    <!-- 批量评分 -->
    <batch-score ref="batchScore" :get-status-type="getStatusType" />
    <!-- 考勤管理 -->
    <attendance-admin ref="attendanceAdmin" :get-status-type="getStatusType" />
    <!-- 备注 -->
    <remark-info ref="remarkInfo" :get-status-type="getStatusType" /></div>
</template>
<script>
import userInfo from '../../components/userInfo/userInfo.vue'
import userExamine from '../../components/userExamine/examine.vue'
import userScore from '../../components/userScore/userScore.vue'
import userVeto from '../../components/userVeto/userVeto.vue'
import reviewSend from '../../components/reviewSend/reviewSend.vue'
import examineSelectScore from '../../components/examineSelectScore/examineSelectScore.vue'
import batchScore from '../../components/batchScore/batchScore.vue'
import attendanceAdmin from '../../components/attendanceAdmin/attendanceAdmin.vue'
import remarkInfo from '@/components/remarkInfo/remarkInfo.vue'
export default {
  components: {
    'user-info': userInfo,
    'user-examine': userExamine,
    'user-score': userScore,
    'user-veto': userVeto,
    'review-send': reviewSend,
    'examine-select-score': examineSelectScore,
    'batch-score': batchScore,
    'attendance-admin': attendanceAdmin,
    'remark-info': remarkInfo
  },
  provide() {
    return {
      reload: this.reload
    }
  },
  data() {
    return {
      // 路由信息传递，注意修改
      // routerLevel -> 当前所属路由等级（1，2，3）
      // routerId -> 当前所属路由编号Id
      routerMessage: {
        routerLevel: '',
        routerId: ''
      },
      // 审核评分一票否决，调用页面获取，无需修改
      getStatusType: [],
      // 控制userInfo是否显示
      isRouterAlive: true
    }
  },
  watch: {
    '$route': function() {
      this.saveRouterInfo()
      this.reload()
    }
  },
  created() {
    // 存储路由信息
    this.saveRouterInfo()
  },
  methods: {
    // 存储路由信息
    saveRouterInfo() {
      if (this.$route.query.routerLevel === undefined) {
        this.routerMessage = JSON.parse(sessionStorage.getItem('routerMessage'))
      } else {
        sessionStorage.setItem('routerMessage', JSON.stringify(this.$route.query))
        this.routerMessage = this.$route.query
      }
    },

    // 审核评分一票否决调用
    getStatus(data) {
      var that = this
      // 根据类型调用不同页面
      if (data.onclickType === 1) {
        // 需要审核
        that.getStatusType = data
        that.$refs.userExamine.showDialog(data)
      } else if (data.onclickType === 2) {
        // 需要评分
        that.getStatusType = data
        that.$refs.userScore.showDialog(data)
      } else if (data.onclickType === 3) {
        // 需要一票否决
        that.getStatusType = data
        that.$refs.userVeto.showDialog(data)
      } else if (data.onclickType === 4) {
        // 需要复核
        that.getStatusType = data
        that.$refs.reviewSend.showDialog(data)
      } else if (data.onclickType === 5) {
        // 需要审核信息
        that.getStatusType = data
        that.$refs.examineSelectScore.showDialog(data)
      } else if (data.onclickType === 6) {
        // 需要批量评分
        that.getStatusType = data
        that.$refs.batchScore.showDialog(data)
      } else if (data.onclickType === 7) {
        // 需要备注
        that.getStatusType = data
        that.$refs.remarkInfo.showDialog(data)
      } else if (data.onclickType === 8) {
        // 需要查看考勤管理
        that.getStatusType = data
        that.$refs.attendanceAdmin.showDialog(data)
      }
    },
    // 刷新页面，原理先关闭再打开
    reload() {
      this.isRouterAlive = false // 先关闭，
      this.$nextTick(function() {
        this.isRouterAlive = true // 再打开
      })
    }
  }
}
</script>
<style lang="scss">

</style>
